package com.device.Controller;

import com.device.Constant.BaseConstant;
import com.device.Entity.Dto.SessionWebUserDto;
import com.device.Service.SbapplyService;
import com.device.annotation.GlobalInterceptor;
import com.device.common.PageResult;
import com.device.common.Result;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/apply")
public class SbapplyController {
    @Resource
    private SbapplyService sbapplyService;

    @RequestMapping("/add")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result add(HttpSession httpSession, Integer deviceid, String remark) {
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.key);
        Integer uid = sessionWebUserDto.getId();
        sbapplyService.apply(deviceid, uid, remark);
        return Result.success();
    }

    @RequestMapping("/list")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result list(Integer pageNo, Integer pageSize, Integer status, HttpSession httpSession) {
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.key);
        Integer uid = sessionWebUserDto.getId();
        PageResult pageResult = sbapplyService.getpage(pageNo, pageSize, status, uid);
        return Result.success(pageResult);

    }
    @RequestMapping("/wxlist")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result wxlist(Integer pageNo, Integer pageSize, Integer status, HttpSession httpSession) {
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.key);
        Integer uid = sessionWebUserDto.getId();
        PageResult pageResult = sbapplyService.getpage2(pageNo, pageSize, status, uid);
        return Result.success(pageResult);

    }

    @RequestMapping("/syslist")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result syslist(Integer pageNo, Integer pageSize, Integer status, HttpSession httpSession) {
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.key);
        Integer uid = sessionWebUserDto.getId();
        PageResult pageResult = sbapplyService.getpage1(pageNo, pageSize, status, uid);
        return Result.success(pageResult);

    }
    @RequestMapping("/syswxlist")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result syswxlist(Integer pageNo, Integer pageSize, Integer status, HttpSession httpSession) {
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.key);
        Integer uid = sessionWebUserDto.getId();
        PageResult pageResult = sbapplyService.getpage3(pageNo, pageSize, status, uid);
        return Result.success(pageResult);

    }
    @RequestMapping("/adminlist")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result adminlist(Integer pageNo, Integer pageSize, Integer status, HttpSession httpSession) {
        PageResult pageResult = sbapplyService.getpage1(pageNo, pageSize, status, null);
        return Result.success(pageResult);

    }
    @RequestMapping("/adminwxlist")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result adminwxlist(Integer pageNo, Integer pageSize, Integer status, HttpSession httpSession) {
        PageResult pageResult = sbapplyService.getpage4(pageNo, pageSize, status, null);
        return Result.success(pageResult);

    }

    @RequestMapping("/edit")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result edit(HttpSession httpSession, Integer id, String remark) {
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.key);
        Integer uid = sessionWebUserDto.getId();
        sbapplyService.editapply(id, uid, remark);
        return Result.success();
    }

    @RequestMapping("/reset")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result reset( Integer id) {

        sbapplyService.resetapply(id);
        return Result.success();
    }
    @RequestMapping("/dglyapply")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result dglyapply( Integer id,Integer glystatus) {

        sbapplyService.dglyapply(id,glystatus);
        return Result.success();
    }
    @RequestMapping("/cglyapply")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result cglyapply( Integer id,Integer status) {

        sbapplyService.cglyapply(id,status);
        return Result.success();
    }
    @RequestMapping("/cglywxapply")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result cglywxapply( Integer id,Integer status) {

        sbapplyService.cglywxapply(id,status);
        return Result.success();
    }

    @RequestMapping("/return")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result returns( Integer id) {

        sbapplyService.returns(id);
        return Result.success();
    }
    @RequestMapping("/delete")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result delete( Integer id) {

        sbapplyService.delete(id);
        return Result.success();
    }

    @RequestMapping("/repair")
    @GlobalInterceptor(checkParam = true, checkLogin = true)
    public Result repair(HttpSession httpSession, Integer id, String remark) {
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.key);
        Integer uid = sessionWebUserDto.getId();
        sbapplyService.repaire(id, uid, remark);
        return Result.success();
    }




}
